package com.tanjie.blackbean.auth.granter;

import com.tanjie.blackbean.pojo.auth.GrantType;
import com.tanjie.blackbean.pojo.exception.BizException;
import lombok.extern.slf4j.Slf4j;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author: tanjie
 * @date: 2022-04-24
 **/
@Slf4j
public class GranterHolder {

    private static final Map<GrantType, ITokenGranter> granterMap = new ConcurrentHashMap<>(16);

    public static void put(GrantType type, ITokenGranter granter) {
        granterMap.put(type, granter);
    }

    public static ITokenGranter get(GrantType grantType) {
        ITokenGranter granter = granterMap.get(grantType);
        if (granter == null) {
            throw new BizException("授权类型:{}没有接口实现", grantType);
        }
        return granter;
    }

}
